<!--
增加用户
-->
<template>
  <card-page>
    <el-form
      ref="form"
      :model="form" 
      label-width="120px"
      style="width: 500px;margin: 0 auto"
    >
      <el-form-item
        prop="instanceId"
        label="实例ID"
        :rules="[{required: true, message: ' '}]"
      >
        <el-input v-model.trim="form.instanceId"></el-input>
      </el-form-item>
      <el-form-item
        prop="number"
        label="呼叫中心电话"
        :rules="[{required: true, message: ' '}]">
        <el-input v-model.trim="form.number"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" :loading="submitting">确定</el-button>
      </el-form-item>
    </el-form>
  </card-page>
</template>

<script>

export default {
  pageProps: {
    title: ({params}) => `${params.mode == 'add' ? '新建' : '修改'}呼叫中心实例`
  },
  data() {
    return {
      mode: this.$params.mode,
      form: {
        instanceId: '',
        number: '',
      },
      submitting: false
    }
  },
  methods: {
    onSubmit() {
      this.$refs.form.validate(async (valid) => {
        if (!valid) return;
        this.submitting = true;
        const ret = await this.$http.post('/api/callcenter', this.form);
        this.submitting = false;
        if (ret.success) {
          this.$message.success('新建成功');
          this.closeCurrentPage();
          this.$params.onSuccess();
        }
      });
    }
  }
}
</script>